package com.stylefeng.guns.modular.payroll.model;

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import cn.afterturn.easypoi.util.PoiPublicUtil;

import java.util.Map;
/**
*工资xecel表解析标题匹配
* @author laoyu
* @date 2018-07-24
*/
public class PayrollImportHandler extends ExcelDataHandlerDefaultImpl<Map<String,Object>> {
    /**
     * 将excel解析的表头转化成对应的map
     * @param map
     * @param originKey
     * @param value
     */
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        if (value instanceof Double) {
            map.put(getRealKey(originKey), PoiPublicUtil.doubleToString((Double) value));
        } else {
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }
    }

    /**
     * 转换excel标题中的字段
     * @param originKey
     * @return
     * @author laoyu
     * @date 2018-07-24
     */
    private String getRealKey(String originKey){

        if (originKey.contains("编号"))
            return "usercode";
        if (originKey.contains("姓名"))
            return "username";
        if (originKey.contains("部门"))
            return "platform";
        if (originKey.contains("入职时间"))
            return "entryTime";
        if (originKey.equals("底薪"))
            return "basicSalary";
        if (originKey.equals("奖金"))
            return "bonus";
        if (originKey.contains("出勤天数"))
            return "attendanceDays";
        if (originKey.contains("实际底薪"))
            return "actualBasicSalary";
        if (originKey.contains("实际奖金"))
            return "actualBonus";
        if (originKey.contains("业绩奖金"))
            return "performanceBonus";
        if (originKey.contains("提成"))
            return "commission";
        if (originKey.contains("无休奖励"))
            return "norepairBonus";
        if (originKey.contains("其他补贴"))
            return "otherSubsidies";
        if (originKey.contains("请假天数"))
            return "leaveDays";
        if (originKey.contains("A扣款"))
            return "leaveDeduction";
        if (originKey.contains("迟到"))
            return "lateArrivals";
        if (originKey.contains("B扣款"))
            return "letaDeduction";
        if (originKey.contains("其它扣款"))
            return "otherDeduction";
        if (originKey.contains("预支PISO"))
            return "advancePiso";
        if (originKey.contains("PISO折RMB"))
            return "advanceRmb";
        if (originKey.contains("实发RMB"))
            return "realRmb";
        if (originKey.contains("应发PISO"))
            return "sendPsio";
        if (originKey.contains("房补"))
            return "roomSupplement";
        if (originKey.contains("实发PISO"))
            return "realPiso";
        if (originKey.contains("备注"))
            return "remarks";




        return null;
    }
}
